package com.yitongmao.common;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.Serializable;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by zhangel on 2016/4/26.
 */
public class UploadParamsResponse implements Serializable{

    /**
     * siteID : 1
     * name : 新空云
     * code : xy
     * appKey : xy-5paw56m65LqR
     * webUrl : http://www.newaircloud.com
     * bucket : newaircloud
     * webRoot : http://oss.mobilereader.cn
     * picRoot : http://img.mobilereader.cn
     * endpoint : oss-cn-hangzhou.aliyuncs.com
     * uploadDir : xy/upload/201604/26/
     * uploadFile : 6cef9010-0b74-11e6-9736-4d0be07bbc5e
     * accessKeyId : Wbc0S2iLmEfUUGhU
     * accessKeySecret : MeK1mkrqdHG49YoItICXVjumSCVauX
     */

    public int siteID;
    public String name;
    public String code;
    public String appKey;
    public String webUrl;
    public String bucket;
    public String webRoot;
    public String picRoot;
    public String endpoint;
    public String uploadDir;
    public String uploadFile;
    public String accessKeyId;
    public String accessKeySecret;

    public static UploadParamsResponse objectFromData(String str) {

        return new Gson().fromJson(str, UploadParamsResponse.class);
    }

    public static UploadParamsResponse objectFromData(String str, String key) {

        try {
            JSONObject jsonObject = new JSONObject(str);

            return new Gson().fromJson(jsonObject.getString(str), UploadParamsResponse.class);
        } catch (JSONException e) {
            e.printStackTrace();
        }

        return null;
    }

    public static List<UploadParamsResponse> arrayUploadParamsResponseFromData(String str) {

        Type listType = new TypeToken<ArrayList<UploadParamsResponse>>() {
        }.getType();

        return new Gson().fromJson(str, listType);
    }

    public static List<UploadParamsResponse> arrayUploadParamsResponseFromData(String str, String key) {

        try {
            JSONObject jsonObject = new JSONObject(str);
            Type listType = new TypeToken<ArrayList<UploadParamsResponse>>() {
            }.getType();

            return new Gson().fromJson(jsonObject.getString(str), listType);

        } catch (JSONException e) {
            e.printStackTrace();
        }

        return new ArrayList();


    }
}
